package cn.steam.ctrl;

import cn.steam.util.ExcelUtil;
import cn.steam.xo.ExcelRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.task.TaskExecutor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author zhang jintao on 2022/05/13
 **/
@RestController
@RequestMapping("excel")
@Api(tags = "Excel")
@Slf4j
public class ExcelCtrl {

    @Resource(name = "myTaskExecutor")
    TaskExecutor taskExecutor;


    @PostMapping
    @ApiOperation("上传解析")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "发行类型，1-会员卡，2-优惠券"), @ApiImplicitParam(name = "name", value = "批次id", defaultValue = "1"), @ApiImplicitParam(name = "ids", value = "steamIds 或者zqIds数组"),})
    public String upload(int id, String name, @RequestParam(value = "ids", required = false) List<Integer> ids, MultipartFile file) throws IOException {
        if (file != null) {
            System.out.println(Arrays.deepToString(ExcelUtil.read(file.getInputStream())));
        }
        System.out.println(ids);
        System.out.println(id);
        System.out.println(name);
        return "ok";
    }

    @PostMapping("post")
    public String post(@RequestBody ExcelRequest request) {
        log.info("收到前端来的一个POST请求，request{}", request);
        System.out.println("手机号码是：" + request.getPhone());
        log.info("手机号码是：{}", request.getPhone());
        log.info("手机号码是集合：{}", Collections.singletonList(request));

        throw new RuntimeException("报错");
    }


}
